package common.view;

import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JComboBox;
import java.awt.Dimension;
import java.awt.event.ActionListener;

import javax.swing.JSeparator;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class IssueSlipView extends JPanel 
{
	private JTextField tfDate;
	private JTable table;
	private MaterialAdderView mAdder;
	private JComboBox cbProject;
	private JComboBox cbCostCenter;
	private JComboBox cbSiteEngineer;
	private JComboBox cbContractor;
	private JButton btnDate;
	private JButton btnSave;
	private JLabel lblIssueNo1;
	private JLabel lblSlipNo1;
	private JComboBox cbBldgNo;
	private JComboBox cbFlatNo;
	
	public IssueSlipView() 
	{
		SpringLayout springLayout = new SpringLayout();
		setLayout(springLayout);
		
		JLabel lblDate = new JLabel("Date:");
		springLayout.putConstraint(SpringLayout.NORTH, lblDate, 10, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, lblDate, 10, SpringLayout.WEST, this);
		lblDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		add(lblDate);
		
		tfDate = new JTextField();
		springLayout.putConstraint(SpringLayout.NORTH, tfDate, 10, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, tfDate, 6, SpringLayout.EAST,lblDate);
		tfDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		tfDate.setColumns(10);
		add(tfDate);
		

		btnDate = new JButton("Cl");
		btnDate.setActionCommand("Cl");
		btnDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, btnDate, 10, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, btnDate, 6, SpringLayout.EAST,tfDate);
		add(btnDate);
		btnDate.setActionCommand("IssueSlipDate");
		
		JLabel lblSlipNo = new JLabel("Slip No :");
		springLayout.putConstraint(SpringLayout.NORTH, lblSlipNo, 10, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, lblSlipNo, 20, SpringLayout.EAST,btnDate);
		lblSlipNo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		add(lblSlipNo);
		
		lblSlipNo1 = new JLabel("xyz");
		springLayout.putConstraint(SpringLayout.NORTH, lblSlipNo1, 10, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, lblSlipNo1, 6, SpringLayout.EAST, lblSlipNo);
		lblSlipNo1.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		add(lblSlipNo1);
		
		JLabel lblIssueNo = new JLabel("Issue No :");
		springLayout.putConstraint(SpringLayout.NORTH, lblIssueNo, 10, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, lblIssueNo, 100, SpringLayout.EAST, lblSlipNo1);
		lblIssueNo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		add(lblIssueNo);
		
		lblIssueNo1 = new JLabel("123");
		springLayout.putConstraint(SpringLayout.NORTH, lblIssueNo1, 10, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, lblIssueNo1, 6, SpringLayout.EAST, lblIssueNo);
		lblIssueNo1.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		add(lblIssueNo1);
		
		JLabel lblProject = new JLabel("Project :");
		lblProject.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, lblProject, 20, SpringLayout.SOUTH, tfDate);
		springLayout.putConstraint(SpringLayout.WEST, lblProject, 10, SpringLayout.WEST,this);
		add(lblProject);
		
		JLabel lblCostCenter = new JLabel("Cost Center :");
		lblCostCenter.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, lblCostCenter, 10, SpringLayout.SOUTH, lblProject);
		springLayout.putConstraint(SpringLayout.WEST, lblCostCenter, 10, SpringLayout.WEST, this);
		add(lblCostCenter);
		
		cbCostCenter = new JComboBox();
		cbCostCenter.setPreferredSize(new Dimension(200, 20));
		cbCostCenter.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, cbCostCenter, 0, SpringLayout.NORTH, lblCostCenter);
		springLayout.putConstraint(SpringLayout.WEST, cbCostCenter, 6, SpringLayout.EAST, lblCostCenter);
		add(cbCostCenter);
		
		cbProject = new JComboBox();
		cbProject.setPreferredSize(new Dimension(200, 20));
		cbProject.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.WEST, cbProject, 0, SpringLayout.WEST, cbCostCenter);
		springLayout.putConstraint(SpringLayout.NORTH, cbProject, 0, SpringLayout.NORTH, lblProject);
		add(cbProject);
		
		JLabel lblSiteEngineer = new JLabel("Site Engineer :");
		lblSiteEngineer.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, lblSiteEngineer, 0, SpringLayout.NORTH, lblProject);
		springLayout.putConstraint(SpringLayout.WEST, lblSiteEngineer, 20, SpringLayout.EAST, cbProject);
		add(lblSiteEngineer);
		
		JLabel lblContractor = new JLabel("Contractor :");
		lblContractor.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, lblContractor, 0, SpringLayout.NORTH, lblCostCenter);
		springLayout.putConstraint(SpringLayout.WEST, lblContractor, 20, SpringLayout.EAST, cbCostCenter);
		add(lblContractor);
		
		cbSiteEngineer = new JComboBox();
		cbSiteEngineer.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		cbSiteEngineer.setPreferredSize(new Dimension(200, 20));
		springLayout.putConstraint(SpringLayout.NORTH, cbSiteEngineer, 0, SpringLayout.NORTH, lblProject);
		springLayout.putConstraint(SpringLayout.WEST, cbSiteEngineer, 6, SpringLayout.EAST, lblSiteEngineer);
		add(cbSiteEngineer);
		
		cbContractor = new JComboBox();
		cbContractor.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		cbContractor.setPreferredSize(new Dimension(200, 20));
		springLayout.putConstraint(SpringLayout.NORTH, cbContractor, 0, SpringLayout.NORTH, lblCostCenter);
		springLayout.putConstraint(SpringLayout.WEST, cbContractor, 0, SpringLayout.WEST, cbSiteEngineer);
		add(cbContractor);
		
		JLabel lblBldgNo = new JLabel("Bldg No :");
		lblBldgNo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, lblBldgNo, 0, SpringLayout.NORTH, lblProject);
		springLayout.putConstraint(SpringLayout.WEST, lblBldgNo, 20, SpringLayout.EAST, cbSiteEngineer);
		add(lblBldgNo);
		
		JLabel lblFlatNo = new JLabel("Flat No :");
		lblFlatNo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, lblFlatNo, 0, SpringLayout.NORTH, lblCostCenter);
		springLayout.putConstraint(SpringLayout.WEST, lblFlatNo, 20, SpringLayout.EAST, cbContractor);
		add(lblFlatNo);
		
		cbBldgNo = new JComboBox();
		cbBldgNo.setPreferredSize(new Dimension(100, 20));
		cbBldgNo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, cbBldgNo, 0, SpringLayout.NORTH, lblProject);
		springLayout.putConstraint(SpringLayout.WEST, cbBldgNo, 6, SpringLayout.EAST, lblBldgNo);
		add(cbBldgNo);
		
		cbFlatNo = new JComboBox();
		cbFlatNo.setPreferredSize(new Dimension(100, 20));
		cbFlatNo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, cbFlatNo, 0, SpringLayout.NORTH, lblCostCenter);
		springLayout.putConstraint(SpringLayout.WEST, cbFlatNo, 0, SpringLayout.WEST, cbBldgNo);
		add(cbFlatNo);
		
		JSeparator separator = new JSeparator();
		springLayout.putConstraint(SpringLayout.NORTH, separator, 10, SpringLayout.SOUTH, lblCostCenter);
		springLayout.putConstraint(SpringLayout.WEST, separator, 10, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.EAST, separator, -10, SpringLayout.EAST, this);
		add(separator);
		
		btnSave = new JButton("Save");
		btnSave.setActionCommand("Save");
		btnSave.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.WEST, btnSave, 200, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.SOUTH, btnSave, -10, SpringLayout.SOUTH, this);
		add(btnSave);
		btnSave.setActionCommand("save");
		
		JScrollPane scrollPane = new JScrollPane();
		springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 10, SpringLayout.SOUTH, separator);
		springLayout.putConstraint(SpringLayout.WEST, scrollPane, 200, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -10, SpringLayout.NORTH, btnSave);
		springLayout.putConstraint(SpringLayout.EAST, scrollPane, -10, SpringLayout.EAST, this);
		add(scrollPane);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null, null, null, null, null, null, null},
			},
			new String[] {
				"Sr.No.", "MCode", "Item", "Specification", "Unit", "Req. Qty", "Issue Qty", "Receiver's Name"
			}
		));
		scrollPane.setViewportView(table);
		
		mAdder = new MaterialAdderView();
		springLayout.putConstraint(SpringLayout.WEST,mAdder,10,SpringLayout.WEST,this);
		springLayout.putConstraint(SpringLayout.NORTH,mAdder,10,SpringLayout.SOUTH,separator);
		springLayout.putConstraint(SpringLayout.EAST, mAdder, -10, SpringLayout.WEST,scrollPane);
		add(mAdder);
	}

	public JTextField getTextFieldDate() {
		return tfDate;
	}

	public void setTextFieldDate(JTextField textFieldDate) {
		this.tfDate = textFieldDate;
	}

	public JTable getTable() {
		return table;
	}

	public void setTable(JTable table) {
		this.table = table;
	}

	public MaterialAdderView getmAdder() {
		return mAdder;
	}

	public void setmAdder(MaterialAdderView mAdder) {
		this.mAdder = mAdder;
	}

	public JTextField getTfDate() {
		return tfDate;
	}

	public void setTfDate(JTextField tfDate) {
		this.tfDate = tfDate;
	}

	public JComboBox getCbProject() {
		return cbProject;
	}

	public void setCbProject(JComboBox cbProject) {
		this.cbProject = cbProject;
	}

	public JComboBox getCbCostCenter() {
		return cbCostCenter;
	}

	public void setCbCostCenter(JComboBox cbCostCenter) {
		this.cbCostCenter = cbCostCenter;
	}

	public JComboBox getCbSiteEngineer() {
		return cbSiteEngineer;
	}

	public void setCbSiteEngineer(JComboBox cbSiteEngineer) {
		this.cbSiteEngineer = cbSiteEngineer;
	}

	public JComboBox getCbContractor() {
		return cbContractor;
	}

	public void setCbContractor(JComboBox cbContractor) {
		this.cbContractor = cbContractor;
	}

	public JButton getBtnDate() {
		return btnDate;
	}

	public void setBtnDate(JButton btnDate) {
		this.btnDate = btnDate;
	}

	public JButton getBtnSave() {
		return btnSave;
	}

	public void setBtnSave(JButton btnSave) {
		this.btnSave = btnSave;
	}

	public JLabel getLblIssueNo1() {
		return lblIssueNo1;
	}

	public void setLblIssueNo1(JLabel lblIssueNo1) {
		this.lblIssueNo1 = lblIssueNo1;
	}

	public JLabel getLblSlipNo1() {
		return lblSlipNo1;
	}

	public void setLblSlipNo1(JLabel lblSlipNo1) {
		this.lblSlipNo1 = lblSlipNo1;
	}

	public JComboBox getCbBldgNo() {
		return cbBldgNo;
	}

	public void setCbBldgNo(JComboBox cbBldgNo) {
		this.cbBldgNo = cbBldgNo;
	}

	public JComboBox getCbFlatNo() {
		return cbFlatNo;
	}

	public void setCbFlatNo(JComboBox cbFlatNo) {
		this.cbFlatNo = cbFlatNo;
	}
	
	public void actionlisteners(ActionListener al)
	{
		btnDate.addActionListener(al);
		btnSave.addActionListener(al);
	}
	
}
